﻿/*
 * Created by SharpDevelop.
 * User: Carlos
 * Date: 02/06/2009
 * Time: 11:01 p.m.
 */
using System;
using System.Collections;
using System.Collections.Generic;
namespace Lambda.Data.NetQuery
{
    /// <summary>
    /// ConditionElement. Representa un elemento de una condición
    /// </summary>
    public abstract class BaseConditionElement
    {
        #region Fields && Properties
            private string name;
            public string Name{
                get { return name; }
            }
            public virtual ConditionElementTypes ContiditionElementType{
                get{
                    return ConditionElementTypes.Single;
                }
            }
        #endregion
        #region Constructors
            public BaseConditionElement(string Name){
                name = Name;
            }
        #endregion
    }
    /// <summary>
    /// ConditionElementRange. Elemento o parte de una condición de tipo rango
    /// </summary>
    public class ConditionElementRange : BaseConditionElement
    {
        #region Fields && Properties
            private BaseConditionElement firstElement;
            public BaseConditionElement FirstElement{
                get { return firstElement; }
            }
            private BaseConditionElement lastElement;
            public BaseConditionElement LastElement{
                get { return lastElement; }
            }
        #endregion
        #region Constructors
            public ConditionElementRange(BaseConditionElement FirstElement, BaseConditionElement LastElement) : base(string.Empty){
                firstElement = FirstElement;
                lastElement = LastElement;
            }
        #endregion
        #region Base Implementation
            public new ConditionElementTypes ContiditionElementType{
                get { return ConditionElementTypes.Range; }
            }
        #endregion
    }
    /// <summary>
    ///  Value. Valor
    /// </summary>
    public class Value : BaseConditionElement
    {
        #region Fields && Properties
            private ValueTypes type;
            public ValueTypes Type{
                get { return type; }
            }
            private object value;
            public bool HasValue{
                get{
                    return (value != null);
                }
            }
        #endregion
        #region Methods
            public DateTime GetDate(){
                return DateTime.Parse((string)value);
            }
            public String GetString(){
                return (string)value;
            }
            public Int16 GetInt16(){
                return Int16.Parse((string)value);
            }
            public Int32 GetInt32(){
                return Int32.Parse((string)value);
            }
            public Int64 GetInt64(){
                return Int64.Parse((string)value);
            }
            public Double GetDouble(){
                return Double.Parse((string)value);
            }
            public Single GetSingle(){
                return Single.Parse((string)value);
            }
            public Char GetChar(){
                return Char.Parse((string)value);
            }
        #endregion
        #region Constructors
            public Value() : base(string.Empty) { type = ValueTypes.String; }
            public Value(ValueTypes Type) : base(string.Empty) { type = Type; }
            private Value(object Value) : this() { value = Value; }
            private Value(object Value, ValueTypes Type) : this(Value) { type = Type; }
            public Value(String Value) : this((object)Value) { }
            public Value(Int16 Value) : this((object)Value) { }
            public Value(Int32 Value) : this((object)Value) { }
            public Value(Int64 Value) : this((object)Value) { }
            public Value(Double Value) : this((object)Value) { }
            public Value(Single Value) : this((object)Value) { }
            public Value(Char Value) : this((object)Value) { }
            public Value(String Value, ValueTypes Type) : this((object)Value, Type) { }
            public Value(Int16 Value, ValueTypes Type) : this((object)Value, Type) { }
            public Value(Int32 Value, ValueTypes Type) : this((object)Value, Type) { }
            public Value(Int64 Value, ValueTypes Type) : this((object)Value, Type) { }
            public Value(Double Value, ValueTypes Type) : this((object)Value, Type) { }
            public Value(Single Value, ValueTypes Type) : this((object)Value, Type) { }
            public Value(Char Value, ValueTypes Type) : this((object)Value, Type) { }
        #endregion
        #region Interface Implementation
            public new ConditionElementTypes ContiditionElementType{
                get { return ConditionElementTypes.Single; }
            }
        #endregion
    }
    /// <summary>
    /// ConditionElementCollection. Elemento de condición de tipo multiple
    /// </summary>
    public class ConditionElementCollection : BaseConditionElement, IList<BaseConditionElement>
    {
        #region Fields && Properties
            private List<BaseConditionElement> items;
            public List<BaseConditionElement> Items{
                get { return items; }
            }     
        #endregion
        #region Constructors
            public ConditionElementCollection() : base (string.Empty){
                items = new List<BaseConditionElement>();
            }
        #endregion
        #region Base Implementation
            public new ConditionElementTypes ContiditionElementType{
                get { return ConditionElementTypes.Multiple; }
            }
        #endregion
        #region Interface Implementation
            public BaseConditionElement this[int index]{
                get { return items[index]; }
                set { items[index] = value; }
            }
            public int IndexOf(BaseConditionElement item){
                return items.IndexOf(item);
            }
            public void Insert(int index, BaseConditionElement item){
                items.Insert(index, item);
            }
            public void RemoveAt(int index){
                items.RemoveAt(index);
            }
            public void Add(BaseConditionElement item){
                items.Add(item);
            }
            public void Clear(){
                items.Clear();
            }
            public bool Contains(BaseConditionElement item){
                return items.Contains(item);
            }
            public void CopyTo(BaseConditionElement[] array, int arrayIndex){
                items.CopyTo(array, arrayIndex);
            }
            public int Count{
                get { return items.Count; }
            }
            public bool Remove(BaseConditionElement item){
                return items.Remove(item);
            }
            public IEnumerator<BaseConditionElement> GetEnumerator(){
                return items.GetEnumerator();
            }
            IEnumerator IEnumerable.GetEnumerator(){
                return items.GetEnumerator();
            }
            public bool IsReadOnly{
                get { return ((ICollection<BaseConditionElement>) items).IsReadOnly; }
            }            
        #endregion
    }
}